package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"group/internal/config"
	"group/models"
)

type ServiceContext struct {
	Config                    config.Config
	Conn                      sqlx.SqlConn
	ChatGroupModel            models.ChatGroupModel
	ChatGroupExtendModel      models.ChatGroupExtendModel
	GroupApplyModel           models.GroupApplyModel
	GroupApplyExtendModel     models.GroupApplyExtendModel
	GroupMemberModel          models.GroupMemberModel
	GroupMemberExtendModel    models.GroupMemberExtendModel
	ChatGroupAggregationModel models.ChatGroupAggregationModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn(c.MySQL.DataSource, c.MySQL.DataSource)
	return &ServiceContext{
		Config:                    c,
		Conn:                      conn,
		ChatGroupModel:            models.NewChatGroupModel(conn, c.Cache),
		ChatGroupExtendModel:      models.NewChatGroupExtendModel(conn, c.Cache),
		GroupApplyModel:           models.NewGroupApplyModel(conn, c.Cache),
		GroupApplyExtendModel:     models.NewGroupApplyExtendModel(conn, c.Cache),
		GroupMemberModel:          models.NewGroupMemberModel(conn, c.Cache),
		GroupMemberExtendModel:    models.NewGroupMemberExtendModel(conn, c.Cache),
		ChatGroupAggregationModel: models.NewChatGroupAggregationModel(conn),
	}
}
